﻿
namespace TestApp.Util
{
    using System;

    public class MatrixInfo
    {
        private MatrixInfo()
        {
        }

        public static MatrixInfo Create(string group, string name, int rows, int cols,
            int nonzeros, string type, bool sym, bool spd = false)
        {
            var matrix = new MatrixInfo();

            matrix.Group = group;
            matrix.Name = name;
            matrix.Id = -1;
            matrix.Rows = rows;
            matrix.Cols = cols;
            matrix.NonZeros = nonzeros;
            matrix.Type = type;
            matrix.IsSymmetric = sym;
            matrix.IsPositiveDefinit = spd;

            return matrix;
        }

        public static MatrixInfo Create(string group, string name, string id,
            string rows, string cols, string nonzeros, string type, string sym, string spd)
        {
            var matrix = new MatrixInfo();

            matrix.Group = group;
            matrix.Name = name;
            matrix.Id = int.Parse(id);
            matrix.Rows = int.Parse(rows);
            matrix.Cols = int.Parse(cols);
            matrix.NonZeros = int.Parse(nonzeros);
            matrix.Type = type;
            matrix.IsSymmetric = sym.Equals("yes");
            matrix.IsPositiveDefinit = spd.Equals("yes");

            return matrix;
        }

        public string Group { get; private set; }
        public string Name { get; private set; }

        public int Id { get; private set; }
        public int Rows { get; private set; }
        public int Cols { get; private set; }
        public int NonZeros { get; private set; }
        public string Type { get; private set; }
        public bool IsSymmetric { get; private set; }
        public bool IsPositiveDefinit { get; private set; }

        public string[] ToArray()
        {
            return new string[]
            {
                Group, Name,
                Rows.ToString(),
                Cols.ToString(),
                NonZeros.ToString(),
                Type,
                IsSymmetric ? "yes": "no",
                IsPositiveDefinit ? "yes": "no"
            };
        }

        public override string ToString()
        {
            return String.Format("{0}/{1} ({2}x{3}) {4} nonzeros",
                Group, Name, Rows, Cols, NonZeros);
        }
    }
}
